*************************************************************************
*******Figure 5: Policy effects on different percentiles of income*******
*************************************************************************

grstyle init
grstyle set plain

cd $PATH

use analysis_main.dta, clear

foreach num of numlist 5(5)95{
g logp`num'= log(1+p`num')
}

tab WAVE, g(yr)

xtset commid WAVE

eststo clear
global score comm denc div econ health house market soc trans edc mart sani

matrix quantiles = J(1,3,.)  
matrix colnames quantiles = B SE Q
matrix identity=J(1,1,1) 
matrix counter=J(1,1,0)  
matrix list quantiles
matrix list identity
matrix list counter


forvalues i=5(5)95{
	matrix counter=counter+identity
	qui:xtreg logp`i' dd post $score yr*, fe vce(cluster commid)
	matrix table=r(table)  
	matrix list table  
	matrix b_se=table[1..2,1..1]'  
	matrix temp=b_se,counter  
	matrix quantiles=quantiles\temp  
	matrix list quantiles  
}

matrix quantiles2=quantiles[2..20,1..3] 	
matrix list quantiles2 
	
svmat quantiles2, names(col) 

gen ciplus90=B+1.645*SE
gen cineg90=B-1.645*SE	

g zero= 0

graph twoway rcap ciplus90 cineg90 Q, sort color(gs10) || bar B Q,  ///
	xlabel(1 "5" 2 "10" 3 "15" 4 "20" 5 "25" 6 "30" 7 "35" 8 "40" 9 "45" 10 "50" ///
		  11 "55" 12 "60" 13 "65" 14 "70" 15 "75" 16 "80" 17 "85" 18 "90" 19 "95", labsize(small))  ///
	ytitle("Estimated income change", margin(small) size(small)) lcolor(gs6) fcolor(none) barwidth(.9) msymbol(none) ///
	legend(order(2 "Coefficient" 1 "90% CI") region(lwidth(none)) size(small))  ///
	graphregion(color(white)) xtitle("Percentiles of income distribution", margin(small) size(small)) 

graph export fig5_incpct.eps, replace
